package net.sk.china.city.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import net.sk.china.city.domain.dto.activity.ActivityInfoDTO;
import net.sk.china.city.domain.dto.activity.ActivitySearchDTO;
import net.sk.china.city.domain.dto.activity.ActivityUpdateDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import net.sk.china.city.controller.base.BaseController;
import net.sk.china.city.domain.dto.AjaxResult;
import net.sk.china.city.service.IArActivityService;
import net.sk.china.city.domain.dto.TableDataInfo;

/**
 * 活动Controller
 * 
 * @author ruoyi
 * @date 2024-04-07
 */
@Api(tags = "活动管理")
@RestController
@RequestMapping("/api/activity")
public class ArActivityController extends BaseController
{
    @Autowired
    private IArActivityService arActivityService;

    /**
     * 查询活动列表
     */
    @ApiOperation("活动列表")
    @PreAuthorize("hasAnyAuthority('activity:management:list')")
    @PostMapping("/list")
    public TableDataInfo<ActivityInfoDTO> list(@RequestBody ActivitySearchDTO activitySearchDTO)
    {
        startPage();
        return arActivityService.selectArActivityList(activitySearchDTO);
    }

//    @ApiOperation("活动审核列表")
    @PostMapping("/approve")
    public TableDataInfo<ActivityInfoDTO> approveList(@RequestBody ActivitySearchDTO activitySearchDTO) {
        return arActivityService.selectActivityApproveList(activitySearchDTO);
    }

    @ApiOperation("删除岗位")
    @PreAuthorize("hasAnyAuthority('activity:management:edit')")
    @DeleteMapping("/job")
    public AjaxResult removeJob(@RequestBody Long jobId)
    {
        return toAjax(arActivityService.deleteJobById(jobId));
    }

    /**
     * 导出活动列表
     */
    @ApiOperation(value = "导出活动", hidden = true)
    @PreAuthorize("hasAnyAuthority('activity:management:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody ActivitySearchDTO activitySearchDTO)
    {
        TableDataInfo<ActivityInfoDTO> activityInfoDTOTableDataInfo = arActivityService.selectArActivityList(activitySearchDTO);
        List<ActivityInfoDTO> list = activityInfoDTOTableDataInfo.getRows();
//        ExcelUtil<ActivityInfoDTO> util = new ExcelUtil<>(ActivityInfoDTO.class);
//        util.exportExcel(response, list, "活动数据");
    }

    /**
     * 获取活动详细信息
     */
    @ApiOperation("活动详情")
    @PreAuthorize("hasAnyAuthority('activity:management:query')")
    @GetMapping(value = "/{pkId}")
    public AjaxResult getInfo(@PathVariable("pkId") Long pkId)
    {
        return success(arActivityService.selectArActivityByPkId(pkId));
    }

    /**
     * 新增活动
     */
    @ApiOperation("发布活动")
    @PreAuthorize("hasAnyAuthority('activity:management:add')")
    @PostMapping
    public AjaxResult add(@RequestBody ActivityUpdateDTO activityUpdateDTO)
    {
        return toAjax(arActivityService.insertArActivity(activityUpdateDTO));
    }

    @ApiOperation("活动审核通过")
    @PreAuthorize("hasAnyAuthority('activity:management:pass')")
    @PostMapping("/pass")
    public AjaxResult passActivity(Long activityId) {
        return toAjax(arActivityService.passActivity(activityId));
    }

    @ApiOperation("活动审核不通过")
    @PreAuthorize("hasAnyAuthority('activity:management:deny')")
    @PostMapping("/deny")
    public AjaxResult denyActivity(Long activityId) {
        return toAjax(arActivityService.denyActivity(activityId));
    }

    /**
     * 修改活动
     */
    @ApiOperation("修改活动")
    @PreAuthorize("hasAnyAuthority('activity:management:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody ActivityUpdateDTO activityUpdateDTO)
    {
        return toAjax(arActivityService.updateArActivity(activityUpdateDTO));
    }

    /**
     * 删除活动
     */
    @ApiOperation("删除活动")
    @PreAuthorize("hasAnyAuthority('activity:management:remove')")
	@DeleteMapping("/{pkIds}")
    public AjaxResult remove(@PathVariable Long[] pkIds)
    {
        return toAjax(arActivityService.deleteArActivityByPkIds(pkIds));
    }
}
